//
// Created by Administrator on 2023/3/19.
//

#ifndef F103CB_USER_H
#define F103CB_USER_H

#include "main.h"
#include <rtthread.h>
#define FONT_SIZE 2

#if   FONT_SIZE == 1
#define FONT_GAP 12
#elif FONT_SIZE == 2
#define FONT_GAP 16
#elif FONT_SIZE == 3
#define FONT_GAP 24
#else
#define FONT_GAP 32
#endif

#define TRUE  1
#define FALSE 0

#define ENCODER_FLITER_SIZE 10
#define RING_BUFF_SIZE      128


#define ARR_LEN(x)  (sizeof(x)/sizeof(x[0]))

#define arr_index_size 3

extern char mon_en[][arr_index_size];
extern char week_en[][arr_index_size];


#define ADC_DEV_NAME           "adc1"      /* ADC 设备名称 */
#define ADC_MQ7_CHANNEL        4           /* ADC 通道 */
#define ADC_MQ137_CHANNEL      6           /* ADC 通道 */
#define ADC_GP2Y10_CHANNEL     14          /* ADC 通道 */
#define REFER_VOLTAGE          3.33f         /* 参考电压 3.3V,数据精度乘以100保留2位小数*/
#define CONVERT_BITS           (1 << 12)   /* 转换位数为12位 */

#define CAL_PPM  10  // 校准环境中PPM值
#define RL       10  // RL阻值

#define GP2Y10_LED  37
#define BEED_PIN    17

#define BEEP_ON     1
#define BEEP_OFF    0
#define TVOC_LIMLT  441
#define CO2_LIMLT   1000

struct screen_t
{
    void (*screen_init)(void);
    uint8_t fps;
    int8_t page_count;
    int8_t page_this;
    uint8_t page_chg;
};

struct sys_tick_t
{
    int screen_tick;
    int rtc_tick;
};
struct ring_buff_t
{
    uint8_t write;
    uint8_t read;
    uint8_t* data_buff;
    uint8_t length;
    void(*buff_init)(uint8_t len);
};

struct adc_dev_t{
    int mq137_adc;
    int mq7_adc;
    int gp2y10_adc;
};
struct sensors_t{
    struct adc_dev_t adc_src;
    uint16_t tvoc;
    uint16_t co2;
    float temp;
    float humi;
    int mq7;
    int mq137;
    int gp2y10;
};
struct weather_t
{
    int temp;
    int humi;
    int wind;
    int sky;
};
#define WEATHER_SUN    0
#define WEATHER_RAIN   1
#define WEATHER_CLOUD  2
typedef struct
{
    struct screen_t     screen;
    struct tm*          location_tm;
    struct ring_buff_t  ringBuff;
    struct sensors_t    sensors;
    struct weather_t    weather_info;
    int weather_flag;
    int adc_device_en;

    int fulsh_lcd_time;
    float mq7_R0;
    void (*page[10])(void);
    void (*tick_up)(void);
    void (*time_updata)(void);
}bsp_t;

extern bsp_t bsp;

void sys_parameter_init(void);
int systeam_thread_init(void);

#endif //F103CB_USER_H
